package com.luoqiz.demo.reflect;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;

import org.junit.Test;

public class ClassloadDemo {

	@Test
	public void resourceTest() {
		System.out.println("***************************************************************************");
		System.out.println("访问系统资源");

		System.out.println("第一种方式得到路径");
		URL url = ClassLoader.getSystemResource("img12.jpg");
		try {
			System.out.println(url.toURI().toString());
		} catch (URISyntaxException e1) {
			e1.printStackTrace();
		}
		System.out.println("第二种方式得到输入流");
		System.out.println("访问jar包内资源，使用ClassLoader.getSystemResourceAsStream");
		InputStream input = ClassLoader.getSystemResourceAsStream("img12.jpg");
		try {
			System.out.println(input.available());
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				input.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
}
